package com.lnu_devteam.zongce.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lnu_devteam.zongce.annotation.AuthCheck;
import com.lnu_devteam.zongce.common.BaseResponse;
import com.lnu_devteam.zongce.common.PageRequest;
import com.lnu_devteam.zongce.common.ResultUtils;
import com.lnu_devteam.zongce.model.enums.RoleEnum;
import com.lnu_devteam.zongce.model.vo.PublicityVO;
import com.lnu_devteam.zongce.service.PublicityService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author xbaozi
 * @version 1.0
 * @classname PublicityController
 * @date 2023-04-15  15:42
 * @description 公示接口
 */
@RestController
@RequestMapping("/publicity")
public class PublicityController {
    @Resource
    private PublicityService publicityService;

    @PostMapping("/publish")
    @ApiOperation("发布公示")
    @AuthCheck(anyRole = {RoleEnum.ADMIN, RoleEnum.SUPER})
    public BaseResponse<Boolean> publishPublicity(String academicYear) {
        boolean res = publicityService.publish(academicYear);
        return ResultUtils.success(res);
    }

    @GetMapping("/page")
    @ApiOperation("分页获取公示数据")
    public BaseResponse<Page<PublicityVO>> pagePublicity(PageRequest pageRequest) {
        Page<PublicityVO> page = publicityService.pagePublicity(pageRequest);
        return ResultUtils.success(page);
    }
}
